package com.wing.storage.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.storage.model.entity.ProductInventoryDetail;
import com.wing.storage.model.entity.ProductStorageWorkOut;
import com.wing.storage.service.ProductInventoryDetailService;
import com.wing.storage.service.ProductStorageWorkOutService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 库存产品详细管理-Controller
 *
 * @author xiayang
 */
@Validated
@Api(value = "库存产品详细管理", tags = "#/storage/productInventoryDetail")
@RestController("productInventoryDetailController")
@RequestMapping("storage/admin/productInventoryDetail")
@RequiredArgsConstructor
public class ProductInventoryDetailController {

    @Autowired
    private ProductInventoryDetailService productInventoryDetailService;

    @ApiOperation(value = "库存产品详细列表", notes = "搜索")
    @GetMapping("/list")
    public PageResult<ProductInventoryDetail> list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit,
            @RequestParam(name = "productDetailId", required = false) Long productDetailId,
            @RequestParam(name = "warehouseId", required = false) Long warehouseId,
            @RequestParam(name = "warehouseAreaId", required = false) Long warehouseAreaId,
            @RequestParam(name = "warehouseShelfId", required = false) Long warehouseShelfId,
            @RequestParam(name = "warehouseShelfSpaceId", required = false) Long warehouseShelfSpaceId,
            @RequestParam(name = "palletBoxId", required = false) Long palletBoxId) {
        Page<ProductInventoryDetail> pg = new Page<>(page, limit);
        Map<String, Object> map = new HashMap();
        map.put("productDetailId", productDetailId);
        map.put("warehouseId", warehouseId);
        map.put("warehouseAreaId", warehouseAreaId);
        map.put("warehouseShelfId", warehouseShelfId);
        map.put("warehouseShelfSpaceId", warehouseShelfSpaceId);
        map.put("palletBoxId", palletBoxId);
        IPage<ProductInventoryDetail> list = productInventoryDetailService.pageList(pg, map);
        return new PageResult<>(list.getRecords(), list.getTotal());
    }


    @ApiOperation(value = "库位-库存产品详细列表", notes = "库位-库存产品详细列表")
    @GetMapping("/listBySpaceCode")
    public JsonResult<List<ProductInventoryDetail>> listBySpaceCode(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit,
            @RequestParam(name = "warehouseShelfSpaceCode", required = true) String warehouseShelfSpaceCode) {
        Page<ProductInventoryDetail> pg = new Page<>(page, 1000);
        Map<String, Object> map = new HashMap();
        map.put("warehouseShelfSpaceCode", warehouseShelfSpaceCode);
        IPage<ProductInventoryDetail> list = productInventoryDetailService.pageList(pg, map);
        return JsonResult.success(list.getRecords());
    }
}
